﻿/*
*验证表单里的用户输入
*
*CreateBy:   Black
*
*CreateDate: 2009-06-30
*
*可以验证的格式:
*  0、清除数据           
*  1、去除左右两端的空格
*  2、判断是否为空
*  3、判断是否是字母
*  4、判断是否是整数
*  5、判断是否是小数
*  6、邮编
*  7、身份证
*  8、固定电话
*  9、移动电话
*  10、传真
*  11、是否真实姓名
*  12、验证是否正确的长日期
*  12、数字字符
*  13、//Emali
*  14 分隔符验证
* 调用方法 JavaScript:dataVer._IsMail(this,'<%=Label1.ClientID %>')"
/*--------------------------------------------------------------------------*/

var dataVer =
{
    //焦点转移错误提示
    _: function(obj, lblname, text) {
        var msgValue = obj.id.replace('txt','lbl');
       
        obj.value = "";
        obj.focus();
        document.getElementById(lblname).style.display = "block";
        try
        {
          document.getElementById(lblname).innerText = document.getElementById(msgValue).innerText +" "+ text;
        }
        catch(e)
        {
          document.getElementById(lblname).innerText =text;
        }
    },
    _L:function()
    {
            var lang = "zh";
            if(self.parent.frames["banner"] != null && self.parent.frames["banner"] != "undefined")
            {
              lang = self.parent.frames["banner"].document.getElementById("hdnPerfLanguage").value;
            }
          if(lang == "zh")
          {
             return true;
          }
          else
          {
            return  false;
          }
      
    },
    //清空lbl记录
    _Empty: function(lblname) {
      //  document.getElementById(lblname).innerText = "";
      //  document.getElementById(lblname).style.className='label_message';
      
      if(document.getElementById(lblname).innerText != "")
      {
        document.getElementById(lblname).style.display ='none';
      }
    },
    //验证数据是否为空
    _$: function(obj) {
        if (obj.value.length > 0) {
            return true;
        }
        else {
            return false;
        }
    },
    //清除数据
    _IsNull: function(obj) {
        obj.value = "";
    },

    //去除左右两端的空格
    _IsTrim: function(obj) {
        obj.value = obj.value.replace(/(^\s*)|(\s*$)/g, "");
        return obj.value;
    },
    //判断是否为空
    _IsEmpty: function(obj, lblname,text) {
        var tempStr = this._IsTrim(obj);
        if (tempStr.length > 0) {
            this._Empty(lblname);
            return true;
        }
        else 
        {
            if(text == '')
            {
                if(this._L())
                {
                  text = '不允许为空!请输入数据';
                }
                else
                {
                text ='Does not allow empty! Please enter data';
                }
            }
            this._(obj, lblname,text);
            return false;
        }
    },
    //判断是否是字母 
    _IsABC: function(obj, lblname) {
        if (this._$(obj)) {
            var temp = this._IsTrim(obj);
            if (temp.match(/^[a-zA-Z]+$/)) {
                this._Empty(lblname);
                return true;
            }
            else 
            {
             var text;
             if(this._L())
                {
                  text = '输入错误,请输入字母!';
                }
                else
                {
                text ='Input error, please enter the letters!';
                }
                this._(obj, lblname, text);
                return false;
            }
        }
    },
    //判断是否是整数  
    _Is123: function(obj, lblname) {
        if (this._$(obj)) {
            var temp = this._IsTrim(obj);
            var text;
            if(temp>0)
            {
                if (temp.match(/^[0-9]+$/)) 
                {
                    this._Empty(lblname);
                    return true;
                }
                else 
                {
                
           
                if(this._L())
                {
                  text = '输入错误,请输入整数!';
                }
                else
                {
                text ='Input error, please enter an integer!';
                }
                    this._(obj, lblname, text);
                    return false;
                }
            }
            else
            {
                if(this._L())
                {
                  text = '输入错误,请输入大于0的整数!';
                }
                else
                {
                text ='Input error, please enter an integer greater than 0!';
                }
               this._(obj, lblname, text);
                    return false;
            }
        }
    },
    
    //判断是否是整数  
    _Is123Or0: function(obj, lblname) {
        if (this._$(obj)) {
            var temp = this._IsTrim(obj);
             var text;
            if(temp>=0)
            {
                if (temp.match(/^[0-9]+$/)) 
                {
                    this._Empty(lblname);
                    return true;
                }
                else 
                {
             
             if(this._L())
                {
                  text = '输入错误,请输入整数!';
                }
                else
                {
                text ='Input error, please enter an integer!';
                }
                    this._(obj, lblname, text);
                    return false;
                }
            }
            else
            {
            
             if(this._L())
                {
                  text = '输入错误,请输入大于等于0的整数!';
                }
                else
                {
                text ='Input error, please enter an integer greater than or equal to 0!';
                }
               this._(obj, lblname, text);
                    return false;
            }
        }
    },
    
      //判断是否是整数  
    _IsNotDecimal: function(obj, lblname) {
        if (this._$(obj)) {
            var temp = this._IsTrim(obj);
              var text;
            if(temp != 0)
            {
                if (temp.match(/^[-]{0,1}[0-9]+$/)) 
                {
                    this._Empty(lblname);
                    return true;
                }
                else {
                
               
             if(this._L())
                {
                  text = '输入错误,请输入正整数或者负整数!';
                }
                else
                {
                text ='Input error, please enter a positive integer or negative integer!';
                }
                    this._(obj, lblname, text);
                    return false;
                }
            }
            else
            {
            
             if(this._Lang())
                {
                  text = '输入错误,请输入正整数或者负整数!';
                }
                else
                {
                text ='Input error, please enter a positive integer or negative integer!';
                }
               this._(obj, lblname, text);
                    return false;
            }
        }
    },
     //判断是否是整数并且判断最大值的验证 
    _Is123Max: function(obj, lblname,num) {
        if (this._$(obj)) {
            var temp = this._IsTrim(obj);
            var text;
            if (temp.match(/^[0-9]+$/)) 
            {
                if(num >=temp)
                {
                this._Empty(lblname);
                return true;
                }
                else
                {
                if(this._L())
                {
                  text = "输入错误,请输入小于等于"+num+" 的整数!";
                }
                else
                {
                text ='Input error, please enter an integer less than or equal to'+num+'!';
                }
                 this._(obj, lblname, text);
                 return false;
                }
            }
            else {
            
              if(this._L())
                {
                  text = "输入错误,请输入整数!";
                }
                else
                {
                text ='Input error, please enter an integer!';
                }
                this._(obj, lblname,text);
                return false;
            }
        }
    },
    //判断是否是小数 小数点最多保留4位
    _Is123x: function(obj, lblname) 
    {
        if (this._$(obj)) {
            var temp = this._IsTrim(obj);
            if (temp.match(/^[0-9]+\.[0-9]{1,4}$/)) {
                this._Empty(lblname);
                return true;
            }
            else {
            var text ;
             if(this._L())
                {
                  text = "输入错误,请输入小数";
                }
                else
                {
                text ='Input error, enter the decimal';
                }
            
                this._(obj, lblname, text);
                return false;
            }
        }
    },
       //判断是否是小数或者整数
    _Is123OrX: function(obj, lblname) 
    {
        if (this._$(obj)) {
            var temp = this._IsTrim(obj);
            if (temp.match(/^\d+(\.{1}\d+)?$/)) {
                this._Empty(lblname);
                return true;
            }
            else {
            
              var text ;
             if(this._L())
                {
                  text = "输入错误,请输入数字!";
                }
                else
                {
                text ='Input error, please enter a number!';
                }
                this._(obj, lblname, text);
                return false;
            }
        }
    },
    //判断是否是邮政编码
    _IsPost: function(obj, lblname) {
//        if (this._$(obj)) {
//            var temp = this._IsTrim(obj);
//            if (temp.match(/^[0-9]{6}$/)) {
//                this._Empty(lblname);
//                return true;
//            }
//            else 
//            {
//             var text ;
//             if(this._L())
//                {
//                  text = "输入错误,请输入邮编!";
//                }
//                else
//                {
//                text ='Input error, please enter the Zip!';
//                }
//                this._(obj, lblname, text);
//                return false;
//            }
//        }
    },
    //身份证
    _IsCode: function(obj, lblname) {
//        if (this._$(obj)) {
//            var temp = this._IsTrim(obj);
//            if (temp.match(/^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/)) {
//                this._Empty(lblname);
//                return true;
//            }
//            else 
//            {
//            var text ;
//             if(this._L())
//                {
//                  text = "输入错误,请输入身份证号!";
//                }
//                else
//                {
//                text ='Input error, enter the ID number!';
//                }
//                this._(obj, lblname, text);
//                return false;
//            }
//        }
    },
    //固定电话 区号与分机号码必须用-隔开
    _IsPhone: function(obj, lblname) {
//        if (this._$(obj)) {
//            var temp = this._IsTrim(obj);
//            if (temp.match(/^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/)) {
//                this._Empty(lblname);
//                return true;
//            }
//            else 
//            {
//             var text ;
//             if(this._L())
//                {
//                  text = "输入错误,请输入电话号,区号与分机号后加 - !";
//                }
//                else
//                {
//                text ='Input error, enter the phone number, area code and extension, add -!';
//                }
//                this._(obj, lblname, text);
//                return false;
//            }
//        }
    },
    //移动电话
    _IsMobile: function(obj, lblname) {
//        if (this._$(obj)) {
//            var temp = this._IsTrim(obj);
//            if (temp.match(/^(13[0-9]|15[0|3|6|7|8|9]|18[8|9])\d{8}$/)) {
//                this._Empty(lblname);
//                return true;
//            }
//            else 
//            {
//             var text ;
//             if(this._L())
//                {
//                  text = "输入错误,请输入手机号!";
//                }
//                else
//                {
//                text ='Input error, please enter your mobile number!';
//                }
//                this._(obj, lblname, text);
//                return false;
//            }
//        }
    },
    //传真
    _IsFax: function(obj, lblname) {
//        if (this._$(obj)) {
//            var temp = this._IsTrim(obj);
//            if (temp.match(/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/)) {
//                this._Empty(lblname);
//                return true;
//            }
//            else {
//              var text ;
//             if(this._L())
//                {
//                  text = "输入错误,请输入传真号!";
//                }
//                else
//                {
//                text ='Input error, enter the fax number!';
//                }
//                this._(obj, lblname, text);
//                return false;
//            }
//        }
    },
    //姓名验证字母或者汉字
    _IsName: function(obj, lblname) {
        if (this._$(obj)) {
            var temp = this._IsTrim(obj);
            if (temp.match(/^[\u4e00-\u9fa5A-Za-z\.]+$/)) {
                this._Empty(lblname);
                return true;
            }
            else 
            {
              var text ;
            if(this._L())
                {
                  text = "输入错误,请输入英文或中文!";
                }
                else
                {
                text ='Input error, enter the English or Chinese!';
                }
                this._(obj, lblname, text);
                return false;
            }
        }
    },
    //验证是否正确的长日期
    _IsTime: function(obj, lblname) {
//        if (this._$(obj)) {
//            var temp = this._IsTrim(obj);
//            temp =temp.replace(".","-").replace("/","-");
//              temp =temp.replace(".","-").replace("/","-");
//            alert(temp);
//            if (temp.match(/^((\d{2}(([02468][048])|([13579][26]))[\-\/\.\s]?((((0?[13578])|(1[02]))[\-\/\.\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\.\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\.\s]?((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/\.\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\.\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\.\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\s(((0?[0-9])|(1[0-9])|(2[0-3]))\:(([0-5][0-9])|([0-9]))(((\s)|(\:(([0-5][0-9])|([0-9]))))?)))?$/)) 
//            {
//                this._Empty(lblname);
//                return true;
//            }
//            else {
//            var text ;
//            if(this._L())
//                {
//                  text = "输入错误,请输入正确日期!";
//                }
//                else
//                {
//                text ='Input error, enter the correct date!';
//                }
//                this._(obj, lblname, text);
//                return false;
//            }
//        }
    },
    //* 数字字符
    _Is123OrABC: function(obj, lblname) {
        if (this._$(obj)) {
            var temp = this._IsTrim(obj);
            if (temp.match(/^[0-9a-zA-Z]+$/)) 
            {
                this._Empty(lblname);
                return true;
            }
            else {
             var text ;
            if(this._L())
                {
                  text = "输入错误,请输入数据!";
                }
                else
                {
                text ='Input error, enter the data!';
                }
                this._(obj, lblname, text);
                return false;
            }
        }
    },
        //Emali
    _IsMail: function(obj, lblname) {
//        if (this._$(obj)) {
//            var temp = this._IsTrim(obj);
//            if (temp.match(/^([a-zA-Z\.0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/)) 
//            {
//                this._Empty(lblname);
//                return true;
//            }
//            else {
//               var text ;
//            if(this._L())
//                {
//                  text = "输入错误,请输入Mail!";
//                }
//                else
//                {
//                text ='Input error, please enter the Mail!';
//                }
//                this._(obj, lblname, text);
//                return false;
//            }
//        }
    },
      //分隔符验证
    _IsSeperatorChar: function(obj, lblname) {
        if (this._$(obj)) {
            var temp = this._IsTrim(obj);
         if (temp.match(/^[\\=\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)\\~\\?\\,\\.\\<\\>\\+\\`\\_\\/\\,-]+$/))
            {
                this._Empty(lblname);
                return true;
            }
            else
             {
                var text ;
            if(this._L())
                {
                  text = "输入错误,请输入分隔符!";
                }
                else
                {
                text ='Input error, enter the separator!';
                }
                this._(obj, lblname, text);
                return false;
            }
        }
    }
    
    
}

//  